using System;
using System.Collections.Generic;
using System.Linq;
using CSI.Directory.Core.Model;
using CSI.Directory.Core.Repositories;
using SubSonic.Repository;

namespace CSI.Directory.Repo
{
    public abstract class RepositoryBase : IRepositoryBase
    {
        protected readonly SimpleRepository repo = new SimpleRepository("Eagle");

        public T GetById<T>(int id) where T : Root, new()
        {
            return repo.Single<T>(t => t.Id == id);
        }

        public T GetByName<T>(string name) where T : Base, new()
        {
            return repo.Single<T>(t => t.Name == name);
        }

        public void AddMany<T>(IList<T> items) where T : class, new()
        {
            repo.AddMany(items);
        }

        public IList<T> GetAll<T>() where T : class, new()
        {
            return repo.All<T>().ToList();
        }

        public void Add<T>(T item) where T : class, new()
        {
            repo.Add<T>(item);
        }

        public int Delete<T>(int key) where T : class, new()
        {
            return repo.Delete<T>(key);
        }

        public int Update<T>(T item) where T : class, new()
        {
            return repo.Update<T>(item);

        }

        public void Delete<T>(IList<T> items) where T : class, new()
        {
            repo.DeleteMany<T>(items);
        }
       
    }
}